import json
from datetime import datetime
import requests

url = "https://drive-pc.quark.cn/1/clouddrive/share/mypage/detail"

headers = {
    "Cookie": "_UP_A4A_11_=wb90813d417c4c3abc8680ee54b7b0ac; _UP_D_=pc; tfstk=eRe6APaUbFY18VdMRNsUVVhFk5kfzP6PfniYqopwDAH9HrZm8cRNsj7bOrUEWR5i7ygb4ovq7lkOcra85jzbmGmxkrUju55FUlqinxQrhTWzjbERmy7ri-DdLxDAzwykk9prnzgy7lS3oFRApQrcRppBnAygtqOJppeIvZ08fqonxJir14hKRKK_dcGsylIrrLu5xGOXAbvxA4SCAIAcPUAqB-2CfjGtxDyPAMT6ifnnA2SCAIfm6DmE_MsBaof..; __pus=7cd92532caf58c6657c6a6aaa13eac17AASlZWx0WsQ11Esx+HNjXPGmPoNN+ZjqhF2ZU79K5SGPs+F6cdFaS+u7WZ7cgnZlgm4PRg0yziBMDHI+bqYi3jHr; __kp=a444b5e0-e14a-11ee-b753-45368fdeeeb2; __kps=AAQbb6s9PluYXsFNTE4AY0Rv; __ktd=YuTFz7Q+YPaswVjyGOpqeg==; __uid=AAQbb6s9PluYXsFNTE4AY0Rv; __puus=08ed40fcad8300859391489a6b36027eAATUZ7b2EwJ7DnLqvM3kgNoSSXzWroAUnsXcwzvoqfqeZzj4cYenQGydIkKeJcUwML31SLhP3AZIRZGpPdh3jJo1uagiVoQfdjUc+AeTevGghskyNVjKF+51bxMIF2J17bo5nRbQf0ox0btmCBcli5kD8toWz1qHwN2BrXFcG4ToOKz6IEhDCzu7qBIIh6gvsfiTIdH/BYxYeHLMjQg8ItI3"}

data = {
    "fileList": [],
    "notice": "短剧机器人可免费使用，如果要对接自己网盘联系微信：wangsihengZzz，短剧资源已更新到4月11日,部分短剧搜索失效也可联系",
    "robotDownload": "https://pan.quark.cn/s/b2a87e12d543",
    "diaryResourceDownload": "https://pan.quark.cn/s/54c3e0292120",
    "onlineSearch": "https://svideo.ppru.cn"
}
fileList = data['fileList']

fixedSize = 500
resultSize = fixedSize
page = 1
dict = {}
num = 1
while resultSize == fixedSize:
    querystring = {"pr": "ucpro", "fr": "pc", "uc_param_str": "", "_page": page, "_size": fixedSize,
                   "_order_field": "title", "_order_type": "desc", "_fetch_total": "1",
                   "_fetch_notify_follow": "1"}
    response = requests.request("GET", url, headers=headers, params=querystring)
    result = json.loads(response.text)
    resultData = result['data']['list']
    for index, item in enumerate(result['data']['list']):
        title = item['title']
        share_url = item['share_url']
        share_time = datetime.fromtimestamp(item['created_at']/100).strftime('%Y-%m-%d %H:%M%S')
        if dict.get(title) != 1 and dict.get(share_url) != 1:
            fileList.append({
                "num":num,
                "title": title,
                'share_url': share_url,
                'share_time':share_time
            })
            num = num + 1
        dict.setdefault(title, 1)
        dict.setdefault(share_url, 1)
    page += 1
    resultSize = len(resultData)

print(data)
print(dict)

with open('data.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False)
